import { Injectable } from '@angular/core';
import { EntityConfig } from '../../core/entity-config.types';
import { PlanOrderPreparationDto } from '../../proxy/joy/erp/basic-archives/production';
import { DatePipe } from '@angular/common';
import { LocalizationService } from '@abp/ng.core';
import { DocumentStatus } from '../../proxy/joy/erp/basic-archives/core/document-status.enum';
import { SupplyType } from '../../proxy/joy/erp/basic-archives/production/supply-type.enum';

@Injectable({
  providedIn: 'root'
})
export class PlanOrderPreparationConfigService {
  datePipe = new DatePipe('zh-CN');

  constructor(
    private localizationService: LocalizationService,
  ) {}

  getConfig(): EntityConfig {
    return {
      entityType: 'Joy.Erp.BasicArchives.Production.PlanOrderPreparation',
      propertys: [
        {
          name: 'Document.Code',
          key: 'document.code',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => item.document.code,
          width: 160,
          show: true,
          order: 0,
          fixed: 0
        },
        {
          name: 'Document.BusinessDate',
          key: 'document.businessDate',
          type: 'date',
          field: (item: PlanOrderPreparationDto) => this.datePipe.transform(item.document.businessDate, 'yyyy-MM-dd'),
          width: 150,
          show: true,
          order: 1,
          fixed: 0
        },
        {
          name: 'Document.OrderType.DisplayName',
          key: 'document.orderType.displayName',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => item.document.orderType?.displayName,
          width: 160,
          show: true,
          order: 2,
          fixed: 0
        },
        {
          name: 'Document.SupplyType',
          key: 'document.supplyType',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => this.l('BasicArchives::EnumText:Joy.Erp.BasicArchives.Production.SupplyType.' + SupplyType[item.document.supplyType]),
          width: 120,
          show: true,
          order: 3,
          fixed: 0
        },
        {
          name: 'Document.ItemMaster.Name',
          key: 'document.itemMaster.name',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => item.document.itemMaster?.name,
          width: 200,
          show: true,
          order: 4,
          fixed: 0
        },
        {
          name: 'Document.DocumentStatus',
          key: 'document.DocumentStatus',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => this.l('BasicArchives::EnumText:Joy.Erp.BasicArchives.Core.DocumentStatus.' + DocumentStatus[item.document.documentStatus]),
          width: 120,
          show: true,
          order: 5,
          fixed: 0
        },
        {
          name: 'ItemCode',
          key: 'itemCode',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => item.itemCode,
          width: 160,
          show: true,
          order: 6,
          fixed: 0
        },
        {
          name: 'ItemName',
          key: 'itemName',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => item.itemName,
          width: 160,
          show: true,
          order: 7,
          fixed: 0
        },
        {
          name: 'ItemSpec',
          key: 'itemSpec',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => item.itemSpec,
          width: 200,
          show: true,
          order: 8,
          fixed: 0
        },
        {
          name: 'Quantity',
          key: 'quantity',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => item.quantity,
          width: 120,
          show: true,
          order: 9,
          fixed: 0
        },
        {
          name: 'IssuedQuantity',
          key: 'issuedQuantity',
          type: 'string',
          field: (item: PlanOrderPreparationDto) => item.issuedQuantity,
          width: 120,
          show: true,
          order: 10,
          fixed: 0
        },
      ]
    };
  }

  private l(key: string, ...parmas: string[]): string {
    return this.localizationService.instant(key, ...parmas);
  }  
} 